/*
 * @Author: 123 dian.peng.zhao@gds.ey.com
 * @Date: 2023-07-25 07:47:37
 * @LastEditors: 123 dian.peng.zhao@gds.ey.com
 * @LastEditTime: 2023-09-07 22:31:13
 * @FilePath: \倒水游戏重构\assets\scripts\utils\Tools.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import { Node, ScrollView, sys, tween, UITransform, v3 } from "cc";


function CreateElementForExecCommand(textToClipboard) {
  var forExecElement = document.createElement("div");
  //在可见区域以外
  forExecElement.style.position = "absolute";
  forExecElement.style.left = "-10000px";
  forExecElement.style.top = "-10000px";
  //将必需的文本写入元素并追加到文档中
  forExecElement.textContent = textToClipboard;
  document.body.appendChild(forExecElement);
  //内容编辑模式在火狐的exec命令方法是必要的
  forExecElement.contentEditable = true;
  return forExecElement;
}

function SelectContent(element) {
  //创建一个范围
  var rangeToSelect = document.createRange();
  rangeToSelect.selectNodeContents(element);
  //选择内容
  var selection = window.getSelection();
  selection.removeAllRanges();
  selection.addRange(rangeToSelect);
}
/**
 * @description: save data into localstorage
 * @return {*}
 */
export function save(key: string, val: string | number | any) {
  if (typeof val === "number") {
    val = ("" + val) as string;
  }
  sys.localStorage.setItem(key, val || "");
}

/**
 * @description: load localstorage data,
 * @return {*}
 */
export function load(key: string, type: 0 | 1 | 2 = 1) {
  let res: any = sys.localStorage.getItem(key);
  if (res) {
    switch (type) {
      case 0:
        break;
      case 1:
        res = Number(res);
        break;
      case 2:
        res = JSON.parse(res);
        break;
    }
    return res;
  } else {
    return null;
  }
}